package com.team.teamproject.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
import com.team.teamproject.R;
import com.team.teamproject.bean.Mod_Homepage_Data;
import java.util.List;

/**
 * Created by Administrator on 2016/11/8.
 */
public class MyHomePageModAdapter extends BaseAdapter {
    Context context;
    List<Mod_Homepage_Data.SecondaryBannersBean> secondary_banners;

    public MyHomePageModAdapter(Context context, List<Mod_Homepage_Data.SecondaryBannersBean> secondary_banners) {
        this.context = context;
        this.secondary_banners = secondary_banners;
    }

    @Override
    public int getCount() {
        return secondary_banners.size();
    }

    @Override
    public Object getItem(int position) {
        return secondary_banners.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = LayoutInflater.from(context);
        ViewHolder holder;
        if (convertView==null) {
           convertView= inflater.inflate(R.layout.item_homepage_mod, null);
            holder=new ViewHolder();
            holder.iv= (ImageView) convertView.findViewById(R.id.iv);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        //取值
        String image_url = secondary_banners.get(position).getImage_url();
        Picasso.with(context).load(image_url).into(holder.iv);
        return convertView;
    }

    static class ViewHolder {

        ImageView iv;
    }
}
